<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>watch</title>
</head>

<body>
  <h1>watch:监听：当数据变化时作出响应</h1>
  <div id="app">
    <button @click="beautiful">change</button>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        arr1: [
          {name: 'jack'}
        ],
        winChips: new Array(11).fill(0)
      },
      // 侦听器
      watch: {
        // 错误的方式：路径只能包含‘.’。不能有方括号
        // 'arr1[0]': {
        //   deep: true,
        //   handler: function (newVal) {
        //     console.log(11,newVal);
        //   }
        // },
        winChips: {
          handler(newValue, oldValue) {
            console.log('newValue')
            
          },
          deep: true
        }
      },
      created() {
        this.$watch(
          // 第一个函数就是处理你要监听的属性，只要将其return出去就行
          function () { 
            return this.arr1[0].name
          },
          function (old, valold) {
            console.log(1234,old, valold);
          }
        )
      },
      methods: {
        beautiful() {
          this.arr1.push(1);
          this.arr1[0].name = 'adf';
          this.winChips.push(66);
        }

      }
    })
  </script>
</body>

</html>